<!DOCTYPE html>
<html>
<head>
{include file="top.tpl"}
<link rel="stylesheet" href="{$css.url}mainframe_min.css">
<link rel="stylesheet" href="{$js.url}plugins/iealert/iealert/css.css">
</head>
<body class="skin-blue">
<div class="wrapper">
	<header class="main-header clearfix">
		<img class="logo-bg" src="{$img.url}banner_bg.jpg" alt="">
		<a href="/" class="logo"></a>
        <!--logo结束-->

          <div class="navbar-left">
          	<nav class='navbar navbar-nav'>
            <ul class="nav navbar-nav">
            {foreach item=topMenu from=$topMenus key=topMenuKey}
			  <li class="dropdown">
			  	<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                  <span class="hidden-xs">{$topMenu.name}</span>
                </a>
                <dl class="dropdown-menu head-sub-nav">
                {foreach item=secondMenu from=$subMenus.$topMenuKey key=secondMenuKey}
                	<dt>{$secondMenu.name}</dt>
                	{if isset($secondMenu.children)} 
                	<dd>
                	{foreach item=thirdMenu from=$secondMenu.children key=thirdMenuKey}
                		<a target="main_frame" href="/{$thirdMenu.module}/{$thirdMenu.controller}/{$thirdMenu.action}">{$thirdMenu.name}</a>
					{/foreach}
                	</dd>
                	{/if}
                {/foreach}
                </dl>	                
			  </li>
			{/foreach}				
            </ul>
            </nav>
        </div>
        <!--下拉导航结束-->

		<div class="navbar-right">
			<ul class="nav navbar-nav">
				<li class="dropdown user-menu">
					<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
						<img src="{$img.url}user2-160x160.jpg" class="user-image" alt="User Image" />
						<span class="hidden-xs">您好！{$username}</span>
					</a>
					 <ul class="dropdown-menu">
						<li><a href="#">修改资料</a></li>
					 	<li><a href="/index/index/loginout">退出登录</a></li>
				    </ul>	 
				</li>
				<li class="dropdown">
					<a href="javascript:;" title="显示/隐藏常用导航" id="js_toggleCommonNav"><i class="fa fa-gears"></i></a>
				</li>
			</ul>
		</div>
		<!--用户信息结束-->
	</header>
	<!--头部结束-->

	<div class="common-use-nav">
		<ul>
			{foreach from=$customMenu  item=custom}
			<li><a target="main_frame" href="/{$custom.module}/{$custom.controller}/{$custom.action}">{$custom.name}</a></li>
			{/foreach}
			<li><a href="javascript:;" title="添加常用菜单" id="js_addUseNav" class="glyphicon glyphicon-plus" aria-hidden="true" data-placement="bottom"></a></li>
		</ul>
		<div id="js_useNavBox" class="hidden">
			<form action="###" method="post" class="user-nav-form" >
				{foreach item=topMenu from=$topMenus key=topMenuKey}

					<div class="control-group">
						<label class="control-label">{$topMenu.name}</label>
					{foreach item=secondMenu from=$subMenus.$topMenuKey key=secondMenuKey}
							<div class="controls clearfix">
								{foreach item=thirdMenu from=$secondMenu.children key=thirdMenuKey}

								<label class="checkbox"><input {if in_array($thirdMenu.menu_id,$customMenuID)}checked{/if} class="select_menu" name='checkitem' type="checkbox" value="{$thirdMenu.menu_id}" >{$thirdMenu.name}</label>
								{/foreach}
							</div>
					{/foreach}
				</div>
				{/foreach}
				<div class="btn-control" data-valtype="button">
                    <button class="btn  btn-primary" id="btn_ok">确定</button>
                    <button class="btn btn-default" id="js_cancelSetNav">取消</button>
                </div>
			</form>
		</div>
	</div>
	<!--常用菜单部分结束-->

	<div id="js_mainWrap">
		<iframe name="main_frame" src="/index/index/main" width="100%" height="100%" frameborder="no" border="none" marginwidth="0" marginheight="0" allowtransparency="yes"></iframe>
	</div>

</div>
{include file="foot.tpl"}
{literal}
<script>

if(window!=top){top.location.href = location.href;}
/*iframe窗口自适应*/
function autoSize(){
	//iframe的高 = 顶部导航区域的高度 - 常用菜单的高度
	var height = $(window).height() - 50 - $(".common-use-nav").outerHeight(true);
	$('#js_mainWrap').css('height', height);
};
$(window).on("resize",function(){
	autoSize();
})		
autoSize();

//显示隐藏常用菜单(用到了本地存储记录状态)
if(window.localStorage){
	if(localStorage.showUseNav==0){
		$(".common-use-nav").hide();
	}
}

$("#js_toggleCommonNav").on("click",function(){

	if($(".common-use-nav").is(":hidden")){
		$(".common-use-nav").show();
		if(window.localStorage){
	 		localStorage.showUseNav=1;
		}
	}
	else{
		$(".common-use-nav").hide();
		if(window.localStorage){
	 		localStorage.showUseNav=0;
		}
	}
	autoSize();			
});

//构建常用菜单popover
$("#js_addUseNav").popover({
	html:true,
	content:$("#js_useNavBox").html()
});

//点击取消按钮隐藏popover
$(document).on("click","#js_cancelSetNav",function(event){
	event.preventDefault();
	$('#js_addUseNav').popover('hide');

});

//导航鼠标划过触发
$('.dropdown').hover(function() {
    $(this).addClass('open');
},
function() {
    $(this).removeClass('open');
});


//选中或取消checkbox
$(document).on("click",".select_menu",function(event){

	if($(this).prop("checked")){

		$(this).prop("checked",true);

	}
	else
	{
		$(this).prop("checked",false);
		$(this).removeAttr("checked");
	}
});

//选择常用菜单
$(document).on("click","#btn_ok",function(event){
	event.preventDefault();
	var num=0;
	var selectedWordIdArr = [];
	$('.popover-content  label').each(function(i,v){
		num=num+1;
		var cb = $(v).find("input[name='checkitem']");

		if(cb.prop("checked")){

			selectedWordIdArr.push(cb.val());
		}
	});
	selectedWordIdArr = $.unique( selectedWordIdArr );

	if(selectedWordIdArr.length >10){
		layer.msg('最多只能添加10个快捷菜单');
		return;
	}
	else
	{
		if(selectedWordIdArr =='')
		{
			layer.confirm('确定要删除所有快捷菜单吗？', function(index){
				var url= "/index/index/custommenus?strValue="+selectedWordIdArr;
				$.ajax({
					type:"GET",
					url: url,
					data: '',
					dataType: "json",
					success:function(res){
						if(res.ret==1){
							layer.alert(res.msg, {icon: 1, title:'提示'}, function(){
								window.location.reload();
							});
						}else{
							layer.alert(res.msg, {icon: 2});
						}
					}
				});
			});
		}
		else{
			var url= "/index/index/custommenus?strValue="+selectedWordIdArr;
			$.ajax({
				type:"GET",
				url: url,
				data: '',
				dataType: "json",
				success:function(res){
					if(res.ret==1){
						layer.alert(res.msg, {icon: 1, title:'提示'}, function(){
							window.location.reload();
						});
					}else{
						layer.alert(res.msg, {icon: 2});
					}
				}
			});
		}

	}

});

</script>
{/literal}
</body>
</html>